package com.plc.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

//@ConfigurationProperties(prefix = "plc")
//@Component
public class PlcConfig {
//
//    @Value("${plc.ljz}")
//    public String ljz;
//
//    public PlcConfig(){
//        System.out.println(getLjz());
//    }
//
//    public String getLjz() {
//        return ljz;
//    }
//
//    public void setLjz(String ljz) {
//        this.ljz = ljz;
//    }

    private static final Properties properties = new Properties();

    static {
        try {
            // 加载自定义配置文件
            InputStream inputStream = PlcConfig.class.getClassLoader().getResourceAsStream("config/custom.properties");
            if (inputStream != null) {
                properties.load(inputStream);
            }else {
                // 处理配置文件未找到的情况
                System.err.println("Custom configuration file 'custom.properties' not found.");
            }
        } catch (IOException e) {
            e.printStackTrace();
            // 处理异常情况
        }
    }

    public static String getProperty(String key) {
        // 获取配置属性值
        return properties.getProperty(key);
    }
}
